package operation;

import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements Operation {
    @Override
    public void work(BookList book) {
        System.out.println("归还图书");
        System.out.println("请输入你要归还的书名：");
        Scanner sc = new Scanner(System.in);
        String borrowedName = sc.nextLine();
        int currentSize = book.getUsedsize();
        for (int i = 0; i < currentSize; i++) {
            if (borrowedName.equals(book.getBooks(i).getName())) {
                if (book.getBooks(i).isIsborrowed() == false) {
                    System.out.println("已经归还了！");//1
                    return;
                }
                book.getBooks(i).setIsborrowed(false);
                System.out.println("归还成功！");//2
                return;
            }
        }
        System.out.println("书架中没有此书，归还失败！");//3
    }
}
